//默认城市
var city = "伊犁";

function loadXMLDoc()
{
    var xmlhttp;
    if (window.XMLHttpRequest)
    {
        //  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
        xmlhttp=new XMLHttpRequest();
    }
    else
    {
        // IE6, IE5 浏览器执行代码
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            var json = JSON.parse(xmlhttp.responseText);
            console.log(json);
            let li=document.querySelectorAll('ul li');
            for (let i=0;i<li.length;i++){
                let tq=document.querySelectorAll(".tianqi");
                tq[i].innerHTML=json.daily_forecast[i].cond.txt_d;
                let sq=document.querySelectorAll(".shidu");
                sq[i].innerHTML=json.daily_forecast[i].tmp.min +"°C";
                let dir = document.querySelectorAll(".fengxiang");
                dir[i].innerHTML = json.daily_forecast[i].wind.dir;

                document.querySelector("#drsg").innerHTML = json.suggestion.drsg.txt;
                document.querySelector("#uv").innerHTML = json.suggestion.uv.txt;
            }

        }
    };
    xmlhttp.open("GET","https://bird.ioliu.cn/weather?city=" + city ,true);
    xmlhttp.send();
}
loadXMLDoc();

//切换城市
document.querySelector("#ipt").addEventListener('change',function(){
    console.log(this.value);
//    赋值城市名字
    city = this.value;
//    执行获取天气的函数
    loadXMLDoc();
});




